// 故障源统计-按月份统计Tab页js文件

function initFaultCountTableYear() {
	initDataTable();
	var d = new Date();
	var currentYear=d.getFullYear();
	$("#countYear1").val(currentYear);
	$('#countYear1').datetimepicker({
		startView: 4,
		minView:4,
		autoclose : true,
		format : 'yyyy'
	});
	changeTableCountYear();
}

function changeTableCountYear() {
	var year=$("#countYear1").val();
	changeTableYear([ {
		name : 'year',
		value : year
	}]);
}

// 图形展示
function initChart1DataByYearAndMonth() {
	var year = $("#countYear1").val();
	var indexV = document.getElementById("monthCountForm:countMonth1").selectedIndex; // 获取当前选择项的索引
	var month = document.getElementById("monthCountForm:countMonth1").options[indexV].value; // 获取当前选择项的值
	$.getJSON("/rest/faultCount/getUploadInfos/"+year+"/"+month,function(result){
		getChart1Data(result);
	});
}

function getChart1Data(result) {
	var indexV = document.getElementById("monthCountForm:dataSource1").selectedIndex;
	var itemValue = document.getElementById("monthCountForm:dataSource1").options[indexV].value;
	var desorgData = eval('('+result[0]+')'); 
	var subCompanyData = eval('('+result[1]+')');
	getYearCountChartData(subCompanyData, itemValue, "chart1")
	getYearCountChartData(desorgData, itemValue, "chart2")
	
	var dataSource;
	if(itemValue == "0") {
		dataSource = "集中录波";
	} else if(itemValue == "1") {
		dataSource = "保护录波";
	} else if (itemValue == "2") {
		dataSource = "保护事件";
	}
	var year = $("#countYear1").val();
	var indexV = document.getElementById("monthCountForm:countMonth1").selectedIndex; // 获取当前选择项的索引
	var month = document.getElementById("monthCountForm:countMonth1").options[indexV].value; // 获取当前选择项的值
	var desorgTitle = year + "年"+month+"月各调度单位故障"+dataSource+"上送情况";
	var subcompanyTitle = year + "年"+month+"月各调度单位故障"+dataSource+"上送情况";
	$("#chart1Title").text(subcompanyTitle);
	$("#chart2Title").text(desorgTitle);
}

function getYearCountChartData(data,itemValue,chartId) {
	var data1 = [];
	if(itemValue == "0") {
		data1 = data.集中录波;
	} else if(itemValue == "1") {
		data1 = data.保护录波;
	} else if (itemValue == "2") {
		data1 = data.保护事件;
	}
	initChart(data1,chartId);
}
